package com.hencoderplus.demo1;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;


/**
 * hencoderplus
 * Created by lzw on 2018/11/1. 13:40:30
 * 邮箱：632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class CicleView extends View {

    private static final int RADIUS = (int) Utils.dp2Px(80);
    private static final int PADDING = (int) Utils.dp2Px(30);
    private static final String TAG = "CirclView";

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    public CicleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CicleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int height  = (PADDING+RADIUS)*2;
        int widht = (PADDING+RADIUS)*2;
       String srt= MeasureSpec.getMode(widthMeasureSpec)==MeasureSpec.EXACTLY?"==MeasureSpec.EXACTLY":"!=MeasureSpec.EXACTLY";
        Log.i(TAG, "onMeasure: 用户："+MeasureSpec.getMode(widthMeasureSpec)+"str="+srt+" width="+MeasureSpec.getSize(widthMeasureSpec)+
        " heightSpec="+MeasureSpec.getMode(heightMeasureSpec)+" height="+MeasureSpec.getSize(heightMeasureSpec));
        Log.i(TAG, "onMeasure before resolveSize: width="+widht+" height:"+height);
        height = resolveSize(height,heightMeasureSpec);
        widht = resolveSize(widht,widthMeasureSpec);
        Log.i(TAG, "onMeasure after resolveSize: width="+widht+" height:"+height);
        setMeasuredDimension(widht,height);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(Color.RED);
        canvas.drawCircle(RADIUS+PADDING,PADDING+RADIUS,RADIUS,paint);
    }
}
